package com.zmn.plat.business.impl.feedback;

import com.alibaba.fastjson.JSON;
import com.zmn.framework.core.http.HttpClientsFactory;
import com.zmn.plat.business.interfaces.feedback.FeedbackBService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * 类描述：
 *
 * @author zmn
 * @since 2022/08/15 15:04
 */
@Service
@Slf4j
public class FeedbackBServiceImpl implements FeedbackBService {

    @Override
    public String getEncrypt(String staffId) {
        if (StringUtils.isEmpty(staffId)) {
            return StringUtils.EMPTY;
        }
        String url = null;
        String response = null;
        try {

            url = "https://log.zmnoa.com/do/collect_dtintegration?userid=" + staffId;
            response = HttpClientsFactory.getHttpClients().get(url);
            if (StringUtils.isEmpty(response)) {
                return StringUtils.EMPTY;
            }
            Map result = JSON.parseObject(response, Map.class);
            log.info("#getEncrypt#find url:{}, request:{}, response:{}", url, staffId, response);
            if (StringUtils.equals(String.valueOf(HttpStatus.SC_OK), result.get("code").toString())) {
                return result.get("encrypt").toString();
            }
        } catch (Exception e) {
            log.error("#getEncrypt#find url:{}, request:{}, response:{}", url, staffId, response, e);
            return StringUtils.EMPTY;
        }
        return StringUtils.EMPTY;
    }
}
